package com.yklx.youke.admin.service.impl;

import com.yklx.youke.admin.mapper.UserRoleMapper;
import com.yklx.youke.admin.service.UserRoleService;
import com.yklx.youke.entity.UserRole;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserRoleServiceImpl implements UserRoleService {

    private final UserRoleMapper userRoleMapper;

    public UserRoleServiceImpl(UserRoleMapper userRoleMapper) {
        this.userRoleMapper = userRoleMapper;
    }

    @Override
    public List<UserRole> getUserRolesByUserId(String userId) {
        return userRoleMapper.getUserRolesByUserId(userId);
    }

    @Override
    public boolean assignRoleToUser(String userId, String roleId) {
        UserRole userRole = new UserRole(userId, roleId);
        return userRoleMapper.assignRoleToUser(userRole) > 0;
    }

    @Override
    public boolean removeRoleFromUser(String userId, String roleId) {
        return userRoleMapper.removeRoleFromUser(userId, roleId) > 0;
    }

    @Override
    public boolean removeAllRolesFromUser(String userId) {
        return userRoleMapper.removeAllRolesFromUser(userId) > 0;
    }
}